package exercises;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

/**
 * Adapter（适配器），适配java.util.Properties
 */
public class FileProperties extends Properties implements FileIO {

    public void readFromFile(String fileName) throws Exception {
        File file = new File(fileName);
        FileInputStream fileInputStream = new FileInputStream(file);
        load(fileInputStream);
    }

    public void writeToFile(String fileName) throws Exception {
        File file = new File(fileName);
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        store(fileOutputStream, fileName);
    }

    public void setValue(String key, String value) {
        setProperty(key, value);
    }

    public String getValue(String key) {
        return getProperty(key);
    }
}
